﻿/*----------------------------------------------------------------
// Copyright (C) 2016 通通优品版权所有。
// 命名空间: STOWaybillMall.Users.Controllers
// 类名：UsersController
// 功能描述：N/A
// 
// 创建标识：Roc.Lee(李鹏鹏) 2017/8/8 17:27:42 TEC-ROCLEE Roc.Lee

// 修改标识：
// 修改描述：
// 
//
//----------------------------------------------------------------*/
using System.Web;
using System.Web.Http;
using STOWaybillMall.Users.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.MallWeb.Application.Users;
using TongTongMall.MallWeb.Application.Users.Dto;
using TongTongMall.MallWeb.WebApi.Controllers;
using TongTongMall.MallWeb.WebApi.Filter;
using TongTongMall.UI;
using TongTongMall.MallWeb.Core.Instance;
using TongTongMall.Common.AutoMapper;

namespace STOWaybillMall.Users.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [RoutePrefix("api/users")]
    public class UsersController : MallWebApiControllerBase
    {
        private readonly IUserAppService _IUserAppService;

        public UsersController(IUserAppService _IUserAppService)
        {
            this._IUserAppService = _IUserAppService;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="input"></param>
        /// <response code="400">Username already in use</response>
        /// <returns></returns>
        //[SwaggerOperation()]
        [Route("user-login"), ApiAuthorization(IsNeedLogin = false)]
        public async Task<LoginSuccessOutput> UserLogin(UserLoginInput input)
        {
            CheckModelState();
            var dto = input.MapTo<UserLoginInputDto>();
            dto.VisitInfo = new VisitInfoDto
            {
                IP = Request.GetClientIpAddress(),
                URI = Request.Headers.Referrer?.ToString(),
                OtherDetail = HttpContext.Current.Request.UserAgent,
                Description = "用户登录"
            };
            return await _IUserAppService.Login(dto);
        }
        /// <summary>
        /// 用户基本信息
        /// </summary>
        /// <returns></returns>
        [Route("user-baseinfo")]
        public GetCurrentLoginInformationsOutput GetCurrentLoginInformations()
        {
            CheckModelState();
            return new GetCurrentLoginInformationsOutput() { Account = Session.UserName };
        }
        /// <summary>
        /// 用户更改密码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Route("user-changepwd")]
        public BaseOutput UserChangePassword(UserChangePasswordInput input)
        {
            CheckModelState();
            return new BaseOutput();
        }
    }
}
